﻿//-------------------------------------------------------------------------------------------------------------------------------------
// Copyright (C) 2005 greatelsoft.com All Rights Reserved
//-------------------------------------------------------------------------------------------------------------------------------------

using System;
using System.Data.Common;
using System.Data;
using System.Data.OleDb;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using GTS.MiniBox.Entity;
using Pub.Class;

namespace GTS.MiniBox.Helper {
    /// <summary>
    /// Box请求日志扩展操作类
    /// 
    /// 修改纪录
    ///     2012-07-25 版本：1.0 系统自动创建此类
    /// 
    /// </summary>
    public partial class RequestLogExtHelper {
        /// <summary>
        /// Box请求日志扩展缓存多少秒 x 5
        /// </summary>
        public static int cacheSeconds = 1440;
        /// <summary>
        /// Box请求日志扩展添加记录
        /// </summary>
        /// <param name="requestLogExt">Box请求日志扩展实体类</param>
        /// <param name="delCache">添加成功后清理的CACHE key，支持正则</param>
        /// <param name="dbkey">存在数据库连接池中的连接key，为空时使用ConnString连接</param>
        /// <returns>添加是否成功</returns>
        public static bool Insert(RequestLogExt requestLogExt, string dbkey = "", string[] delCache = null) {
            string strSql = new SQL().Insert(RequestLogExt._)
                .Value(RequestLogExt._RequestID, requestLogExt.RequestID)
                .Value(RequestLogExt._UpResult, requestLogExt.UpResult)
                .Value(RequestLogExt._DownResult, requestLogExt.DownResult)
                .Value(RequestLogExt._LoginDate, requestLogExt.LoginDate)
                .ToString();
            bool istrue = dbkey.IsNullEmpty() ? Data.ExecSql(strSql) == 1 : Data.Pool(dbkey).ExecSql(strSql) == 1;
            if (delCache.IsNull()) return istrue;
            foreach (string s in delCache) {
                if (s.IndexOf("(") == -1 || s.IndexOf("[") == -1)
                    Cache2.Remove(s.IndexOf("Cache_") == -1 ? "GTS.MiniBox.RequestLogExtCache_" + s : s);
                else
                    Cache2.RemoveByPattern(s.IndexOf("Cache_") == -1 ? "(GTS.MiniBox.RequestLogExtCache_" + s + ")" : s);
            }
            return istrue;
        }
        /// <summary>
        /// Box请求日志扩展添加记录
        /// </summary>
        /// <param name="requestLogExt">Box请求日志扩展实体类</param>
        /// <returns>添加是否成功</returns>
        public static bool Insert(RequestLogExt requestLogExt, string dbkey = "") {
            return Insert(requestLogExt, dbkey, null);
        }
    }
}

